<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>重置密码</title>
    <link rel="stylesheet" href="<?=userassets?>component/pear/css/pear.css" /> 
    <style>
        body {
            background: linear-gradient(to bottom, #141e30, #243b55); /* 调整后的渐变背景 */
            color: #fff;
            font-family: 'Roboto', sans-serif; /* 现代字体 */
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            overflow: hidden; /* 隐藏滚动条 */
            transition: all 0.3s ease; /* 全局过渡效果 */
        }
        
        /* 覆盖 layui 弹窗的样式 */
        .layui-layer-content {
            color: #333 !important; /* 设置弹窗文字颜色为深色 */
        }

        .card {
            width: 400px;
            background-color: rgba(255, 255, 255, 0.06);
            border-radius: 10px;
            padding: 40px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
            backdrop-filter: blur(5px);
            border: 1px solid rgba(255, 255, 255, 0.08);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }

        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
        }

        .form-group {
            margin-bottom: 25px;
        }

        label {
            display: block;
            font-size: 16px;
            font-weight: 500;
            margin-bottom: 8px;
            color: #eee;
        }

        input[type="password"] { /* 修改为 password 类型 */
            width: 100%;
            padding: 12px 15px;
            font-size: 16px;
            border-radius: 5px;
            border: none;
            background-color: rgba(255, 255, 255, 0.12);
            color: #fff;
            box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
            transition: background-color 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
        }

        input[type="password"]::placeholder {
            color: #bbb;
            font-style: italic;
        }

        input[type="password"]:focus {
            outline: none;
            box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3), 0 0 5px rgba(0, 123, 255, 0.5);
            background-color: rgba(255, 255, 255, 0.18);
            border-color: rgba(0, 123, 255, 0.7);
        }


        button {
            width: 100%;
            padding: 14px 20px;
            font-size: 18px;
            font-weight: 500;
            color: #fff;
            background: linear-gradient(to right, #6a5af9, #4589f3);
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background 0.3s ease, box-shadow 0.3s ease;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
        }

        button:hover {
            background: linear-gradient(to left, #6a5af9, #4589f3);
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
        }


    </style>
</head>
<body>

    <div class="card">
        <form class="layui-form" action="">
            <div class="form-group">
                <label for="newPassword">新密码</label>
                <input type="password" id="newPassword" name="newPassword" placeholder="请输入新密码" required lay-verify="required">
            </div>
            <div class="form-group">
                <label for="confirmPassword">确认密码</label>
                <input type="password" id="confirmPassword" name="confirmPassword" placeholder="请再次输入新密码" required lay-verify="required|confirmPassword">
            </div>
            <button type="submit" lay-submit lay-filter="reset">重置密码</button>
        </form>
    </div>

    <script src="<?=userassets?>component/layui/layui.js"></script>
    <script src="<?=userassets?>component/pear/pear.js"></script>
    
    <script>
        layui.use(['form', 'jquery', 'layer'], function(){
            let form = layui.form;
            let $ = layui.jquery;
            let layer = layui.layer;

            // 自定义验证规则
            form.verify({
                confirmPassword: function(value){
                    if(value !== $('#newPassword').val()){
                        return '两次输入的密码不一致！';
                    }
                }
            });

            // 获取 URL 中的 Token (示例)
            function getQueryString(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return decodeURIComponent(r[2]); return null;
            }

            var token = getQueryString("token");
            console.log("Token:", token); // 在控制台输出 Token，方便调试

            //监听提交
            form.on('submit(reset)', function(data){
                // 发送 AJAX 请求到后端
                $.ajax({
                    url: '/api/ResetPassword', //  后端接口地址
                    type: 'POST',
                    data: {
                        newPassword: data.field.newPassword,
                        token: token //  将 Token 也发送到后端
                    },
                    dataType: 'json',
                    success: function(res){
                        if(res.code === 200){
                            // 重置成功
                            layer.msg('密码重置成功！', {
                                icon: 1,
                                time: 2000
                            }, function(){
                                location.href = '/user/login'; // 跳转到登录页面
                            });
                        } else {
                            // 重置失败
                            layer.msg(res.msg, {
                                icon: 2,
                                time: 2000
                            });
                        }
                    },
                    error: function(xhr, status, error){
                        // 请求出错
                        layer.msg('网络错误，请检查网络连接！', {
                            icon: 2,
                            time: 2000
                        });
                        console.error('AJAX 请求出错:', status, error);
                    }
                });
                return false;
            });
        });
    </script>
</body>
</html>
